package main

import (
	"fmt"
	"github.com/Unknwon/goconfig"
	"os"
	"os/exec"
	"path/filepath"
)

func InitConfig() {
	CurrentPath, _ := exec.LookPath(os.Args[0])
	dir := filepath.Dir(CurrentPath)
	cfg, err := goconfig.LoadConfigFile(fmt.Sprintf("%s/conf/td.cnf", dir))
	if err != nil {
		log.Error("Load the config file error > %v", err)
	}
	DB_HOST = cfg.MustValue("db", "host", "127.0.0.1")
	DB_PORT = cfg.MustValue("db", "port", "3306")
	DB_USER = cfg.MustValue("db", "user", "root")
	DB_PASSWORD = cfg.MustValue("db", "password", "")
	DB_NAME = cfg.MustValue("db", "name", "monitor")
	POOL_SIZE = cfg.MustInt("db", "pool_size", 20)
	ROTATE = cfg.MustBool("server", "rotate", true)
	MAX_DAY = cfg.MustInt("server", "max_day", 7)
	LOG_FILE = cfg.MustValue("server", "log_file", "logs/server.log")
}
